package org.example.consumer.demo;

import org.shushan.framework.web.request.RequestHoldHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * @author zhigang.li
 * @date 2022/8/23
 
 
 */
@SpringBootApplication
@RestController
@ComponentScan(basePackages = {"org.example", "org.shushan"})
public class ConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }

    @Value("${server.port}")
    public Integer port;

    @GetMapping("consumer")
    public String consumer() {
        HttpServletRequest httpServletRequest = RequestHoldHelper.getHttpServletRequest();
        Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String element = headerNames.nextElement();
            System.out.println(element+":"+httpServletRequest.getHeader(element));
        }
        return "consumer:" + port;
    }


}
